package com.ldx.blog.controller;

import com.ldx.blog.common.exception.BlogException;
import com.ldx.blog.pojo.request.UserLoginRequest;
import com.ldx.blog.pojo.response.UserInfoResponse;
import com.ldx.blog.pojo.response.UserLoginResponse;
import com.ldx.blog.sevice.UserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import javax.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/user")
@RestController
@Slf4j
public class UserInfoController {
    @Resource(name = "userServiceImpl")
    UserService userService;
    @RequestMapping("/login")
    public UserLoginResponse Login(@RequestBody @Validated UserLoginRequest userLoginRequest) throws BlogException {
        log.info("用户登录 名称："+ userLoginRequest.getUserName());
        return userService.login(userLoginRequest);
    }
    @RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(Integer userId){
        log.info("查询用户id:"+userId);
        return userService.getUserInfo(userId);
    }
    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull(message = "博客id不能为空") Integer blogId) throws BlogException {
        log.info("查询博客id:"+blogId);
        return userService.getAuthorInfo(blogId);
    }
}
